package com.xingkeduo.business.transformation.json;

import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.xingkeduo.pojo.dto.ShopCraftsmanServiceDto;
import com.xingkeduo.util.pojo.base.BaseJson;
import com.xingkeduo.util.tool.CommonUtil;

import java.util.Iterator;
import java.util.List;

/**
 * 外部 夕桐调用
 *
 * @Description:
 * @Author:gaozifeng
 * @Date 2019/5/29 21:18
 **/
public class ShopCraftsmanServiceDtoJTO extends BaseJson {

    public static ObjectNode toJson(ShopCraftsmanServiceDto table) throws Throwable {
        ObjectNode root = MAPPER.createObjectNode();
        if (table != null) {

            if (0L != table.getCraftsmanId()) {
                root.put("craftsmanId", table.getCraftsmanId());
            }
            if (null != table.getServiceList()) {
                root.putPOJO("serviceList", CraftsmanServiceJTO.toJson(table.getServiceList()));
            }
        }
        return root;
    }

    public static ArrayNode toJson(List<ShopCraftsmanServiceDto> tables) throws Throwable {
        ArrayNode root = MAPPER.createArrayNode();

        if (!CommonUtil.isEmpty(tables))
            for (Iterator<ShopCraftsmanServiceDto> iterator = tables.iterator(); iterator.hasNext(); ) {
                root.add(toJson(iterator.next()));
            }

        return root;
    }
}
